home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEMP / GNU / flex / Incompatib < prev    next >
Text File  |  1995-06-28  |  7KB  |  240 lines

  1. Incompatibilities
  2. Previous: <C++=>C> * Next: <Diagnostics=>Diagnostic> * Up: <Top=>!Root>
  3.  
  4. #Wrap on
  5. {fH3}Incompatibilities with {fCode}lex{f} and POSIX{f}
  6.  
  7. {fCode}flex{f} is a rewrite of the AT&T Unix {fCode}lex{f} tool (the two
  8. implementations do not share any code, though), with some
  9. extensions and incompatibilities, both of which are of
  10. concern to those who wish to write scanners acceptable to
  11. either implementation.  Flex is fully compliant with the
  12. POSIX {fCode}lex{f} specification, except that when using {fEmphasis}%pointer{f}
  13. (the default), a call to {fEmphasis}unput(){f} destroys the contents of
  14. {fCode}yytext{f}, which is counter to the POSIX specification.
  15.  
  16. In this section we discuss all of the known areas of
  17. incompatibility between flex, AT&T lex, and the POSIX
  18. specification.
  19.  
  20. {fCode}flex's{f} {fEmphasis}-l{f} option turns on maximum compatibility with the
  21. original AT&T {fCode}lex{f} implementation, at the cost of a major
  22. loss in the generated scanner's performance.  We note
  23. below which incompatibilities can be overcome using the {fEmphasis}-l{f}
  24. option.
  25.  
  26. {fCode}flex{f} is fully compatible with {fCode}lex{f} with the following
  27. exceptions:
  28.  
  29. #Indent +4
  30.  
  31.  - The undocumented {fCode}lex{f} scanner internal variable {fCode}yylineno{f}
  32. is not supported unless {fEmphasis}-l{f} or {fEmphasis}%option yylineno{f} is used.
  33. {fCode}yylineno{f} should be maintained on a per-buffer basis, rather
  34. than a per-scanner (single global variable) basis.  {fCode}yylineno{f} is
  35. not part of the POSIX specification.
  36.  
  37.  
  38.  - The {fEmphasis}input(){f} routine is not redefinable, though it
  39. may be called to read characters following whatever
  40. has been matched by a rule.  If {fEmphasis}input(){f} encounters
  41. an end-of-file the normal {fEmphasis}yywrap(){f} processing is
  42. done.  A ``real'' end-of-file is returned by
  43. {fEmphasis}input(){f} as {fCode}EOF{f}.
  44.  
  45. Input is instead controlled by defining the
  46. {fCode}YY\_INPUT{f} macro.
  47.  
  48. The {fCode}flex{f} restriction that {fEmphasis}input(){f} cannot be
  49. redefined is in accordance with the POSIX
  50. specification, which simply does not specify any way of
  51. controlling the scanner's input other than by making
  52. an initial assignment to {fCode}yyin{f}.
  53.  
  54.  
  55.  - The {fEmphasis}unput(){f} routine is not redefinable.  This
  56. restriction is in accordance with POSIX.
  57.  
  58.  
  59.  - {fCode}flex{f} scanners are not as reentrant as {fCode}lex{f} scanners.
  60. In particular, if you have an interactive scanner
  61. and an interrupt handler which long-jumps out of
  62. the scanner, and the scanner is subsequently called
  63. again, you may get the following message:
  64.  
  65. #Wrap off
  66. #fCode
  67. fatal flex scanner internal error--end of buffer missed
  68. #f
  69. #Wrap on
  70.  
  71. To reenter the scanner, first use
  72.  
  73. #Wrap off
  74. #fCode
  75. yyrestart( yyin );
  76. #f
  77. #Wrap on
  78.  
  79. Note that this call will throw away any buffered
  80. input; usually this isn't a problem with an
  81. interactive scanner.
  82.  
  83. Also note that flex C++ scanner classes {fEmphasis}are{f}
  84. reentrant, so if using C++ is an option for you, you
  85. should use them instead.  See "Generating C++
  86. Scanners" above for details.
  87.  
  88.  
  89.  - {fEmphasis}output(){f} is not supported.  Output from the {fEmphasis}ECHO{f}
  90. macro is done to the file-pointer {fCode}yyout{f} (default
  91. {fCode}stdout{f}).
  92.  
  93. {fEmphasis}output(){f} is not part of the POSIX specification.
  94.  
  95.  
  96.  - {fCode}lex{f} does not support exclusive start conditions
  97. (%x), though they are in the POSIX specification.
  98.  
  99.  
  100.  - When definitions are expanded, {fCode}flex{f} encloses them
  101. in parentheses.  With lex, the following:
  102.  
  103. #Wrap off
  104. #fCode
  105. NAME    [A-Z][A-Z0-9]\*
  106. %%
  107. foo\{NAME\}?      printf( "Found it\\n" );
  108. %%
  109. #f
  110. #Wrap on
  111.  
  112. will not match the string "foo" because when the
  113. macro is expanded the rule is equivalent to
  114. "foo[A-Z][A-Z0-9]\*?" and the precedence is such that the
  115. '?' is associated with "[A-Z0-9]\*".  With {fCode}flex{f}, the
  116. rule will be expanded to "foo([A-Z][A-Z0-9]\*)?" and
  117. so the string "foo" will match.
  118.  
  119. Note that if the definition begins with {fEmphasis}^{f} or ends
  120. with {fEmphasis}${f} then it is {fEmphasis}not{f} expanded with parentheses, to
  121. allow these operators to appear in definitions
  122. without losing their special meanings.  But the
  123. {fEmphasis}<s>, \/{f}, and {fEmphasis}<<EOF>>{f} operators cannot be used in a
  124. {fCode}flex{f} definition.
  125.  
  126. Using {fEmphasis}-l{f} results in the {fCode}lex{f} behavior of no
  127. parentheses around the definition.
  128.  
  129. The POSIX specification is that the definition be enclosed in
  130. parentheses.
  131.  
  132.  
  133.  - Some implementations of {fCode}lex{f} allow a rule's action to begin on
  134. a separate line, if the rule's pattern has trailing whitespace:
  135.  
  136. #Wrap off
  137. #fCode
  138. %%
  139. foo|bar<space here>
  140.   \{ foobar\_action(); \}
  141. #f
  142. #Wrap on
  143.  
  144. {fCode}flex{f} does not support this feature.
  145.  
  146.  
  147.  - The {fCode}lex{f} {fEmphasis}%r{f} (generate a Ratfor scanner) option is
  148. not supported.  It is not part of the POSIX
  149. specification.
  150.  
  151.  
  152.  - After a call to {fEmphasis}unput(){f}, {fCode}yytext{f} is undefined until
  153. the next token is matched, unless the scanner was
  154. built using {fEmphasis}%array{f}.  This is not the case with {fCode}lex{f}
  155. or the POSIX specification.  The {fEmphasis}-l{f} option does
  156. away with this incompatibility.
  157.  
  158.  
  159.  - The precedence of the {fEmphasis}\{\}{f} (numeric range) operator
  160. is different.  {fCode}lex{f} interprets "abc\{1,3\}" as "match
  161. one, two, or three occurrences of 'abc'", whereas
  162. {fCode}flex{f} interprets it as "match 'ab' followed by one,
  163. two, or three occurrences of 'c'".  The latter is
  164. in agreement with the POSIX specification.
  165.  
  166.  
  167.  - The precedence of the {fEmphasis}^{f} operator is different.  {fCode}lex{f}
  168. interprets "^foo|bar" as "match either 'foo' at the
  169. beginning of a line, or 'bar' anywhere", whereas
  170. {fCode}flex{f} interprets it as "match either 'foo' or 'bar'
  171. if they come at the beginning of a line".  The
  172. latter is in agreement with the POSIX specification.
  173.  
  174.  
  175.  - The special table-size declarations such as {fEmphasis}%a{f}
  176. supported by {fCode}lex{f} are not required by {fCode}flex{f} scanners;
  177. {fCode}flex{f} ignores them.
  178.  
  179.  
  180.  - The name FLEX\_SCANNER is \#define'd so scanners may
  181. be written for use with either {fCode}flex{f} or {fCode}lex{f}.
  182. Scanners also include {fCode}YY\_FLEX\_MAJOR\_VERSION{f} and
  183. {fCode}YY\_FLEX\_MINOR\_VERSION{f} indicating which version of
  184. {fCode}flex{f} generated the scanner (for example, for the
  185. 2.5 release, these defines would be 2 and 5
  186. respectively).
  187.  
  188. #Indent
  189.  
  190. The following {fCode}flex{f} features are not included in {fCode}lex{f} or the
  191. POSIX specification:
  192.  
  193. #Wrap off
  194. #fCode
  195. C++ scanners
  196. %option
  197. start condition scopes
  198. start condition stacks
  199. interactive\/non-interactive scanners
  200. yy\_scan\_string() and friends
  201. yyterminate()
  202. yy\_set\_interactive()
  203. yy\_set\_bol()
  204. YY\_AT\_BOL()
  205. <<EOF>>
  206. <\*>
  207. YY\_DECL
  208. YY\_START
  209. YY\_USER\_ACTION
  210. YY\_USER\_INIT
  211. \#line directives
  212. %\{\}'s around actions
  213. multiple actions on a line
  214. #f
  215. #Wrap on
  216.  
  217. plus almost all of the flex flags.  The last feature in
  218. the list refers to the fact that with {fCode}flex{f} you can put
  219. multiple actions on the same line, separated with
  220. semicolons, while with {fCode}lex{f}, the following
  221.  
  222. #Wrap off
  223. #fCode
  224. foo    handle\_foo(); ++num\_foos\_seen;
  225. #f
  226. #Wrap on
  227.  
  228. is (rather surprisingly) truncated to
  229.  
  230. #Wrap off
  231. #fCode
  232. foo    handle\_foo();
  233. #f
  234. #Wrap on
  235.  
  236. {fCode}flex{f} does not truncate the action.  Actions that are not
  237. enclosed in braces are simply terminated at the end of the
  238. line.
  239.  
  240.